/**
 * Created by kayak-lic on 16/11/9.
 */
import React from 'react';
import util from 'util';
import {Switch,Input,Row,Col,Button,Table ,Modal,Form,Collapse,Card,Radio,Tabs} from 'antd';
import { SearchDemo,RightButton,ColsEdit,Simeditor } from 'kpl';
import sys_dict from "sys_dict";

class ResResultSelect extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            tblSource: [],
            isLoading: false,
            totalCount:0,
        };
        this.searchParams = {
            "page": 1,
            "rows": sys_dict.defaultPageSize.toString(),
            "qry_channel_id":""
        };
    }
    // 刷新123123123
    refresh(paramdic){
        //params.qry_channel_id=params.channel_id;
        this.setState({isLoading: true});
            util.httpRequest({type: "POST", url: 'register130101.json',plattype:'app/' , params: paramdic, success: function (result) {
                this.setState({
                    tblSource: result.rows,
                    totalCount:result.total,
                    isLoading: false,
                });
            }.bind(this)});
        }

    search(params){
        params.start_date = util.date2str(params.start_date);
        params.end_date = util.date2str(params.end_date);
        params.page = "1";
        params.rows = sys_dict.defaultPageSize.toString();

        this.refresh(params);
    }

    onShowSizeChange(current, pageSize) {
        let params = this.searchParams;
        params.rows = pageSize;
        params.page = current;
        this.refresh(params);
    }

    onChange(page) {
        let params = this.searchParams;
        params.page = page;
        this.refresh(params);
    }

    componentDidMount(){
        this.refresh(this.searchParams);
    }

    config(){
        const pagination = {
            total: this.state.totalCount,
            showSizeChanger: true,
            showQuickJumper: true,
            isLoading: false,
            pageSizeOptions: sys_dict.pageSizeOptions,
            defaultPageSize: sys_dict.defaultPageSize,
            onShowSizeChange: this.onShowSizeChange.bind(this),
            onChange: this.onChange.bind(this),
        };

        return {
            tableConfig: {
                pagination: pagination,
                dataSource: this.state.tblSource,
                columns: [
                    {
                        title: '手机号',
                        dataIndex: 'mobile',
                        key: 'mobile',
                    },{
                        title: '用户名',
                        dataIndex: 'login_name',
                        key: 'login_name',
                    },{
                        title: '注册渠道',
                        dataIndex: 'channel_type',
                        key: 'channel_type',
                        render: function (value, data, rowIndex) {
                            var str = util.convert("channel_type", value);
                            return str;
                        }
                    },{
                        title: '注册日期',
                        dataIndex: 'create_date',
                        key: 'create_date',
                        render: function (value, data, rowIndex) {
                            var str = util.dateStrFormat(data.create_date+data.create_time, "DT");
                            return str;
                        }
                    }]
                 },
        }
    }

    render(){

        let config=this.config();
        const searchConfig= {
            searchTitle:"查询条件",
            searchInit:{login_name:"",start_date:"",end_date:"",channel_type:""},
            searchField: [
                [
                    {propsname:"手机号",propsKey:"mobile",propsType:"input",key:"111"},
                    {propsname: "注册渠道", propsKey: "channel_type", propsType: "select", key: "112"},
                ],
                [
                    {propsname: "注册时间", propsKey: "start_date", propsType: "datepicker", key: "113"},
                    {propsname: "至", propsKey: "end_date", propsType: "datepicker", key: "114"},
                ],
            ]};
        return (
            <div>
                <SearchDemo search={this.search.bind(this)} searchConfig={searchConfig} ></SearchDemo>
                <Table {...config.tableConfig}></Table>
            </div>
        );
    }
}

export default ResResultSelect;